<?php

/***@property string $sql_string
*@property integer $source_config
*@property string $desc_config
*@property string $fileds_mapping
*@property string $before_sql
*@property string $node_name
*@property string $node_desc
 */

namespace backend\modules\tool\models;

class Node extends \backend\modules\tool\models\BaseModel
{
    /**
     * @inheritdoc
     */
    public static $create_sql="CREATE TABLE if not exists `t_node_back_fill` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `sql_string` text COMMENT '数据源SQL语句',
  `source_config` int(50) DEFAULT NULL COMMENT '数据来源',
  `desc_config` varchar(50) DEFAULT NULL COMMENT '数据去向',
  `fileds_mapping` text COMMENT '字段映射',
  `before_sql` text COMMENT '预执行SQL',
  `node_name` varchar(50) DEFAULT NULL COMMENT '节点名称',
  `node_desc` varchar(50) DEFAULT NULL COMMENT '节点描述',
  `desc_table` varchar(255) DEFAULT NULL COMMENT '数据去向表',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8;";
    public static function tableName()
    {
        return '{{%t_node_back_fill}}';
    }
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['source_config','desc_config'],'required'],
            [['source_config','is_bind','batch_size'],'integer'],
            [['desc_config','node_name','node_desc'],'string','max'=>'500'],
            [['fileds_mapping','desc_table','sql_string','before_sql','run_fun','way','pid'],'string']
        ];
    }
    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'sql_string'=>'数据源SQL语句',
            'source_config'=>'数据来源数据库',
            'desc_config'=>'数据去向数据库',
            'desc_table'=>'数据去向表',
            'fileds_mapping'=>'字段映射',
            'before_sql'=>'预执行SQL--****--分割多条',
            'node_name'=>'节点名称',
            'node_desc'=>'节点描述',
            'run_fun'=>'执行的php程序',
            'way'=>"主键冲突处理方式",
            "is_bind"=>"是否使用参数绑定",
            "batch_size"=>"批量插入数量",
            'pid'=>"整库同步名称"
        ];
    }
    public function beforeDelete()
    {
        $node=DataSourceTask::find()->where(["task_id"=>$this->id])->one();
        if(!empty($node)){
            $node->delete();
        }
        return parent::beforeDelete(); // TODO: Change the autogenerated stub
    }
}